app.controller('SaleRuleModalCtrl', function ($scope, $modalInstance, toaster, param) {

	$scope.dplist = [];

	$scope.submitting = false;
	$scope.param = param;
	if ($scope.param.data == null) {
		$scope.param.data = {};
	}

	$scope.loaddplist = function () {
		$scope.dplist =
			[
				{ id: 1, name: "直接折扣" },
				{ id: 2, name: "满减" },
				{ id: 3, name: "随机优惠" }
			];
		if ($scope.param.data.type != undefined) {
			var id = $scope.param.data.type;
			$scope.dplist.selected = $scope.dplist[id - 1];
		} else {
			$scope.dplist.selected = $scope.dplist[0];
		}
	};
	$scope.loaddplist();

	$scope.ok = function () {
		if ($scope.myForm.$valid) {
			$scope.param.data.type = $scope.dplist.selected.id;
			$modalInstance.close($scope.param);
		}
	};

	$scope.cancel = function () {
		$modalInstance.dismiss('cancel');
	};

	$scope.$watch('dplist.selected', function (newVal, oldVal) { // jshint unused:false
		if (newVal) {
			newVal = $scope.dplist.selected.id;
			if (newVal == 1) $scope.hint = "输入公式：折扣的金额（元）。例：10";
			if (newVal == 2) $scope.hint = "输入公式：price>满足的金额（元）?要减去的金额（元）:0。 例：price>100?5:0";
			if (newVal == 3) $scope.hint = "随机折扣的最小值,随机折扣的最大值。例：5,20";
		}
	});
});